package com.tms.app.tms.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tms.app.tms.R;
import com.tms.app.tms.bean.Node;
import com.tms.app.tms.bean.TestBean;
import com.tms.app.tms.bean.response.TaskInfoRes;
import com.tms.app.tms.utils.TimeUtil;

import java.util.List;

/**
 * Created by happy on 2017/8/26.
 */

public class NodeAdapter extends BaseQuickAdapter<Node, BaseViewHolder> {
    public NodeAdapter() {
        super(R.layout.item_list_node);
    }



    @Override
    protected void convert(BaseViewHolder helper, Node item) {
        helper.getView(R.id.item_img_tree_small).setVisibility(View.VISIBLE);
        helper.getView(R.id.node_layout).setVisibility(View.VISIBLE);
        helper.getView(R.id.item_text_status).setVisibility(View.VISIBLE);
        helper.getView(R.id.node_layout_header).setVisibility(View.GONE);
        if (helper.getAdapterPosition()==0){
            helper.getView(R.id.view_hiver).setVisibility(View.GONE);
            helper.getView(R.id.node_layout).setVisibility(View.GONE);
            helper.getView(R.id.item_img_tree_small).setVisibility(View.GONE);
            helper.getView(R.id.item_text_status).setVisibility(View.GONE);

            helper.getView(R.id.node_layout_header).setVisibility(View.VISIBLE);
            if (item.getStatus()==0)//0:未开始；1:执行中; 2:已完成
                helper.getView(R.id.item_text_status_header).getBackground().setLevel(0);
            else
                helper.getView(R.id.item_text_status_header).getBackground().setLevel(1);
        }
        if(helper.getAdapterPosition()==getData().size()-1){
            helper.getView(R.id.view_hiver).setVisibility(View.GONE);
            helper.getView(R.id.node_layout).setVisibility(View.GONE);
            helper.getView(R.id.item_img_tree_small).setVisibility(View.GONE);
            helper.getView(R.id.item_text_status).setVisibility(View.GONE);
            helper.getView(R.id.text_node_name_header).setVisibility(View.GONE);

            helper.getView(R.id.node_layout_header).setVisibility(View.VISIBLE);
            if (item.getStatus()==2)//0:未开始；1:执行中; 2:已完成
                helper.getView(R.id.item_text_status_header).getBackground().setLevel(3);
            else
                helper.getView(R.id.item_text_status_header).getBackground().setLevel(2);
        }

        if (helper.getAdapterPosition()==getData().size()-2)
            helper.getView(R.id.item_img_tree_small).setVisibility(View.GONE);
        // 派车单状态 0 待执行，1执行中，2 司机已完成3，确认已完成

        if (item.getPlanIdShowType()==1||item.getPlanIdShowType()==11
            ||item.getPlanIdShowType()==2||item.getPlanIdShowType()==12
                ||item.getPlanIdShowType()==3||item.getPlanIdShowType()==13)
        {
            helper.getView(R.id.text_next).setVisibility(View.VISIBLE);
        }
        else
        {
            helper.getView(R.id.text_next).setVisibility(View.INVISIBLE);
        }


        helper.setText(R.id.text_order_no,item.getWaybillNo());
        helper.setText(R.id.text_node_name,item.getStationName() + "  "+ TimeUtil.getTimeFormat(item.getPlanTime()));
        if (item.getStationName()!=null)
            helper.setText(R.id.text_node_name_header,item.getStationName() + "  "+ TimeUtil.getTimeFormat(item.getPlanTime()));
        helper.setText(R.id.text_node_adress,item.getStationAddress());
        helper.setText(R.id.item_text_status,item.getDoTypeName()+"");

        ImageView imageViewSmall=helper.getView(R.id.item_img_tree_small);
        ImageView imageViewBig=helper.getView(R.id.item_img_tree_big);
        TextView textStatus=helper.getView(R.id.item_text_status);



        imageViewSmall.getBackground().setLevel(item.getStatus());
        imageViewBig.getBackground().setLevel(item.getStatus());
        textStatus.getBackground().setLevel(item.getStatus());
        setBusiType(helper,item.getBusiType()+"");

    }

    private void setBusiType(BaseViewHolder helper,String ... type){
        TextView textView1=helper.getView(R.id.text_fabu_type1);
        TextView textView2=helper.getView(R.id.text_fabu_type2);
        TextView textView3=helper.getView(R.id.text_fabu_type3);

        textView1.setVisibility(View.GONE);
        textView2.setVisibility(View.GONE);
        textView3.setVisibility(View.GONE);

        for (String s : type) {
            switch (s){
                case "0":
                    textView1.setVisibility(View.VISIBLE);
                    break;
                case "1":
                    textView2.setVisibility(View.VISIBLE);
                    break;
                case "2":
                    textView3.setVisibility(View.VISIBLE);
                    break;
            }
        }

    }
}
